home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 301 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.2 KB

  1. Path: fido.asd.sgi.com!austern
  2. From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: class.union questions
  5. Date: 06 Feb 1996 10:27:03 PST
  6. Organization: Comp Sci, University of Melbourne
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4f7l8h$t0e@mulga.cs.mu.OZ.AU>
  9. References: <v01530500ad38ee830c96@[194.163.74.11]> <KANZE.96Feb5132431@slsvewt.lts.sel.alcatel.de>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: 6 Feb 1996 13:32:01 GMT
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBVAwUBMRedlEy4NqrwXLNJAQEyCgH/TchVO/723+i5IVua3O0ZQZ+yIVD8uvmF
  14.     WlbnZCUaNpuguTBuodNuBwiU/0yL6CJsZRSV8C3hOk5U4z3cPyvbnw==
  15.     =lcpr
  16. Originator: austern@isolde.mti.sgi.com
  17.  
  18. kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763) writes:
  19.  
  20. >dirk@becker.adviser.com (Dirk Becker) writes:
  21. >
  22. >|> In Section 9.6.1 Unions [class.union] there is a large collection of
  23. >|> restrictions on the union itself and on candidate member classes.
  24. >|> I would like to ask for reasons of several of them:
  25. >
  26. >One of the principle goals was that a union be compatible with a C
  27. >union, at least in use.  One of the rules is that the addresses of all
  28. >of the elements in the union compare equal to the address of the union
  29. >itself, when cast to the appropriate type.
  30. >
  31. >|> a)  "A union shall not have base classes. A union shall not be used as
  32. >|>      a base class."
  33. >
  34. >Without this rule, you either break the address rule, or you impose
  35. >some special class layout on unions.
  36.  
  37. Nevertheless, contrary to what you seem to be implying,
  38. that rule is not necessary for C compatibility.
  39.  
  40. C++ structs can be very different to C structs, but C compatibility
  41. is preserved for a certain category of C++ structs, namely POD-structs.
  42. In the case of unions, the same thing could have been done -
  43. rule (a) could have been dropped, yet C compatibility could still
  44. have been be supported for POD-unions.
  45.  
  46. --
  47. Fergus Henderson                 WWW: http://www.cs.mu.oz.au/~fjh
  48. fjh@cs.mu.oz.au                  PGP: finger fjh@128.250.37.3
  49. ---
  50. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  51.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy is
  52.   in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
  53.